# $Id: PKGBUILD 136836 2011-09-02 07:59:01Z andyrtr $
# Maintainer: Andreas Radke <andyrtr@archlinux.org>

pkgbase=icedtea-web-java7
pkgname=('icedtea-web-java7' 'icedtea-web-java7-doc')
pkgver=1.4
pkgrel=1
arch=('i686' 'x86_64')
url="http://icedtea.classpath.org/wiki/IcedTea-Web"
license=('GPL2')
makedepends=('jdk7-openjdk' 'zip' 'libxtst' 'npapi-sdk' 'rhino' 'junit' 'firefox' 'chromium' 'epiphany')
noextract=${pkgbase/-java7/}-$pkgver.tar.gz # due to broken path names in the tarball that fails with LANG=C in our chroot
source=(http://icedtea.classpath.org/download/source/${pkgbase/-java7/}-$pkgver.tar.gz)
sha256sums=('e53a41fa132e086fa8d17cadf1e7e38cb3ab99577277949fbcae4ab8705245fb')

_javaver=7
_jvmdir=/usr/lib/jvm/java-${_javaver}-openjdk

build() {
  # extract it
  cd "$srcdir"
  LANG=en_US.UTF-8 bsdtar -x -f ${srcdir}/${pkgbase/-java7/}-$pkgver.tar.gz

  cd "${srcdir}"/icedtea-web*
  ./configure --prefix=${_jvmdir} \
      --datarootdir=/usr/share \
      --with-jdk-home=${_jvmdir} \
      --with-browser-tests \
      --with-firefox=/usr/bin/firefox \
      --with-chromium=/usr/bin/chromium \
      --with-epiphany=/usr/bin/epiphany
   make
}

check() {
  cd "${srcdir}"/icedtea-web*
  # as more tests have been added some are expectged to fail
  # see http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2012-March/017566.html
  make -k check || /bin/true
}


package_icedtea-web-java7() {

  pkgdesc="provides a Free Software web browser plugin running applets written in the Java programming language and an implementation of Java Web Start, originally based on the NetX project"
  depends=('jre7-openjdk' 'desktop-file-utils')
  provides=('java-web-start=7')
  replaces=('icedtea-web')
  install=${pkgname}.install

  cd "${srcdir}"/icedtea-web* #${pkgname}-${_date}"
  # possible make target (see bottom of Makefile.am: install-exec-local install-data-local
  make DESTDIR="${pkgdir}" install-exec-local install-data-local

  # Install desktop files.
  install -m755 -d ${pkgdir}/usr/share/{applications,pixmaps}
  install -m644 javaws.png ${pkgdir}/usr/share/pixmaps
  install -m644 {javaws,itweb-settings}.desktop ${pkgdir}/usr/share/applications
  # remove splitted doc files
  rm -rf ${pkgdir}/usr/share/doc

  # link binaries into /usr/bin + jre/bin
  install -m755 -d ${pkgdir}/usr/bin
  install -m755 -d ${pkgdir}/${_jvmdir}/jre/bin
  pushd ${pkgdir}/${_jvmdir}/bin
  for file in *; do
    ln -sf ${_jvmdir}/bin/${file} ${pkgdir}/usr/bin
    ln -sf ${_jvmdir}/bin/${file} ${pkgdir}/${_jvmdir}/jre/bin
  done
  popd

  # link the mozilla-plugin - test it here http://www.java.com/en/download/help/testvm.xml
  install -m755 -d ${pkgdir}/usr/lib/mozilla/plugins/
  ln -sf ${_jvmdir}/lib/IcedTeaPlugin.so ${pkgdir}/usr/lib/mozilla/plugins/
}

package_icedtea-web-java7-doc() {

  pkgdesc="icedtea-web browser plugin + Java WebStart - documentation files"
  replaces=('icedtea-web-doc')

  cd "${srcdir}"/icedtea-web*
  make DESTDIR="${pkgdir}" install-data-local
  # remove javaws about and man page
  rm -rf ${pkgdir}/usr/lib
  rm -rf ${pkgdir}/usr/share/man
  rm -rf ${pkgdir}/usr/share/icedtea-web # conflicting and unneeded file it seems
}
